package com.demo.servlet.utils;


import com.aspose.words.*;
import com.demo.servlet.utils.doGenerate;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Date;

/** 
* @Description: Document测试 
* @Param:  
* @return:  
* @Author: lizexin 
* @Date: 2020/12/7 
*/
public class DemoDocument {

    public static final String localPath = "E:\\bigdatali\\output\\";
    public static final long datast = new Date().getTime();

    public  static void CreatDocument(Document document,DocumentBuilder builder, String title, int fontSize, int indent)throws Exception{

        builder.getFont().setName("黑体"); //设置字体
        builder.getFont().setSize(fontSize); // 字体大小
        builder.getFont().setBold(true); //标题加粗
        builder.getParagraphFormat().setFirstLineIndent(indent); //首字不缩进
        builder.getParagraphFormat().setAlignment(ParagraphAlignment.LEFT); //水平居中对齐; //左对齐
        builder.writeln(title);

        ByteArrayOutputStream dstStream = new ByteArrayOutputStream();
        //document.save();

        //Table table = new Table(document);

    }


    public static void main(String[] args)throws Exception  {
        //创建一个新的文档
        Document document = new Document(localPath+datast+ "DocumentBuilderAndSave Out.docx");
        ByteArrayOutputStream dstStream = new ByteArrayOutputStream();
        document.save(dstStream,SaveFormat.DOCX);
        ByteArrayInputStream srcStream = new ByteArrayInputStream(dstStream.toByteArray());

        //增加内容
        DocumentBuilder builder = new DocumentBuilder(document);



        CreatDocument(document,builder,"HELLOWORD",20,60);



    }
}
